<template>
	<div class="wareHous-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="state.queryParams" ref="queryForm" :inline="true">
				<el-form-item label="任务号">
					<el-input v-model="state.queryParams.tasknumber" placeholder="任务号" clearable />
				</el-form-item>
				<el-form-item label="物料">
					<el-input v-model="state.queryParams.materialCode" placeholder="物料编码" clearable />
				</el-form-item>
				<el-form-item label="任务类型">
					<el-select v-model="state.queryParams.Type" placeholder="请选择任务类型" clearable>
						<el-option v-for="(value, key) in TaskTypeEnum" :key="key" :label="value" :value="Number(key)">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询
						</el-button>
						<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
					</el-button-group>
					<el-button type="primary" icon="ele-Plus" @click="add">添加
					</el-button>
					<el-button type="danger" icon="ele-Warning" @click="batchDeleteWcs">批量删除</el-button>
					<el-button type="primary" icon="ele-Download" @click="exportDate">导出</el-button>
					<!-- <el-button type="primary" icon="ele-Download" @click="downloadTemplate">模版</el-button> -->
					<el-button type="danger" icon="ele-Warning" @click="emergencyOperation">优先下发</el-button>
					<el-button type="primary" icon="ele-Check" @click="OnTaskclick(1)">启动</el-button>
					<el-button type="primary" icon="ele-Close" @click="OnTaskclick(2)">取消</el-button>

				</el-form-item>


			</el-form>
		</el-card>

		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<el-table :data="state.WcsData" style="width: 100%" v-loading="state.loading" border
				@selection-change="handleSelectionChange">
				<el-table-column type="selection" prop="id" width="55" align="center" />
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="taskNumber" label="任务号" width="150" align="center" show-overflow-tooltip />
				<el-table-column prop="type" label="任务类型" align="center" show-overflow-tooltip>
					<template #default="scope">
						{{ TaskTypeEnum[scope.row.type as keyof typeof TaskTypeEnum] || '未知类型' }}
					</template>
				</el-table-column>
				<el-table-column prop="trayCode" label="托盘码" align="center" show-overflow-tooltip />
				<el-table-column prop="materialCode" label="物料号" align="center" show-overflow-tooltip />
				<el-table-column prop="hoistOpening" label="出入口" align="center" show-overflow-tooltip />
				<el-table-column prop="downDate" label="下达时间" align="center" show-overflow-tooltip />
				<el-table-column prop="finishDate" label="完成时间" align="center" show-overflow-tooltip />
				<el-table-column prop="sortId" label="排序" align="center" show-overflow-tooltip />
				<!-- <el-table-column prop="status" label="任务状态" align="center" show-overflow-tooltip>

					<template #default="scope">
						{{ typeof TASK_STATUS_MAP[scope.row.status as keyof typeof TASK_STATUS_MAP] === 'object' ?
							typeof TASK_STATUS_MAP[scope.row.status as keyof typeof TASK_STATUS_MAP] === 'object'
								? TASK_STATUS_MAP[scope.row.status as keyof typeof TASK_STATUS_MAP]?.type
								: TASK_STATUS_MAP[scope.row.status as keyof typeof
								TASK_STATUS_MAP] : TASK_STATUS_MAP[scope.row.status as keyof typeof TASK_STATUS_MAP] || '未知类型'
						}}
					</template>
				</el-table-column> -->


				<el-table-column prop="status" label="任务状态" align="center">
					<template #default="scope">
						<el-tag>
							{{ {
								1: '未开始',
								2: '进行中',
								3: '退回',
								4: '已完成',
								5: '已取消',
								6: '异常'
							}[scope.row.status as number || 0] || '未知状态' }}
						</el-tag>

					</template>
				</el-table-column>


				<el-table-column prop="sn" label="SN" align="center" show-overflow-tooltip />
				<el-table-column prop="channel" label="暂存通道" align="center" show-overflow-tooltip />
				<el-table-column prop="countNumber" label="发送次数" align="center" show-overflow-tooltip />
				<el-table-column prop="resPonse" label="响应" align="center" show-overflow-tooltip />

				<el-table-column prop="isEnable" label="启用状态" width="80" align="center">
					<template #default="scope">
						<el-tag v-if="scope.row.isenable === 1"> 启用 </el-tag>
						<el-tag type="danger" v-else> 未启用 </el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="200" fixed="right" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text type="primary"
							@click="openEditWarehous(scope.row)"> 编辑 </el-button>
						<el-button size="small" text type="danger" @click="delWarehous(scope.row)"> 删除 </el-button>
						<el-button size="small" text type="info" @click="Detail(scope.row.taskNumber)"> 下发步骤</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination v-model:currentPage="state.tableParams.page" v-model:page-size="state.tableParams.pageSize"
				:total="state.tableParams.total" :page-sizes="[10, 20, 50, 100]" size="small" background
				@size-change="handleSizeChange" @current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper" />
		</el-card>


		<EditWcstask ref="editEditWcstaskRef" :title="state.editWcstaskTitle" @handleQuery="handleQuery" />
		<!-- <DetailsWcstask ref="detailsEditWcstaskRef" :title="state.detailsWcstaskTitle" @handleQuery="handleQuery" /> -->
		<el-dialog title="任务详情" v-model="statedetail.details" width="80%" height="40%">
			<el-form :model="state.queryParams" ref="queryForm" :inline="true">
				<!-- <el-form-item label="序号">
					<el-input v-model="state.queryParams.tasknumber" placeholder="任务号" clearable />
				</el-form-item> -->

				<el-button type="primary" icon="ele-Play" @click="Onclick(1)">启动</el-button>
				<el-button type="primary" icon="ele-Close" @click="Onclick(2)">取消</el-button>
			</el-form>

			<el-table :data="statedetail.AgvactionsData" style="width: 100%" v-loading="state.loading" border
				@selection-change="handleSelectiondetailsChange">

				<el-table-column type="selection" prop="id" width="55" align="center" />

				<el-table-column type="index" label="序号" width="55" align="center" />

				<el-table-column prop="taskId" label="任务号" align="center" show-overflow-tooltip />
				<el-table-column prop="palletcode" label="托盘码" align="center" show-overflow-tooltip />
				<el-table-column prop="startPosition" label="起始点位" align="center" show-overflow-tooltip />
				<el-table-column prop="targetPosition" label="目标点位" align="center" show-overflow-tooltip />
				<el-table-column prop="deviceId" label="设备id" align="center" show-overflow-tooltip />
				<el-table-column prop="actionType" label="动作类型" align="center" show-overflow-tooltip>
					<template #default="scope">

						<el-tag
							:type="scope.row.actionType === 1 ? 'info' : scope.row.actionType === 0 ? 'primary' : 'default'">
							{{ scope.row.actionType === 1 ? '反馈' : scope.row.actionType === 0 ? '行动' : '未知类型' }}
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="actionGroupType" label="动作分组类型" align="center" show-overflow-tooltip>
					<template #default="scope">
						{{ ActionTypeEnum[scope.row.actionGroupType as keyof typeof ActionTypeEnum] || '未知类型' }}
					</template>
				</el-table-column>
				<el-table-column prop="status" label="动作状态" align="center" show-overflow-tooltip>
					<template #default="scope">
						{{ ActionStatusEnum[scope.row.status as keyof typeof ActionStatusEnum] || '未知类型' }}
					</template>
				</el-table-column>
				<!-- <el-table-column prop="status" label="状态" align="center" show-overflow-tooltip /> -->
				<el-table-column prop="istype" label="出库入库" align="center" show-overflow-tooltip />
				<el-table-column label="操作" width="200" fixed="right" align="center" show-overflow-tooltip>
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text type="primary" @click="OnDclick(scope.row)"> 取消
						</el-button>
						<el-button size="small" text type="danger" @click="OnDclick(scope.row)"> 启动 </el-button>
					</template>
				</el-table-column>
			</el-table>

			<el-pagination v-model:currentPage="statedetail.detailsTableParams.page"
				v-model:page-size="statedetail.detailsTableParams.pageSize"
				:total="statedetail.detailsTableParams.total" :page-sizes="[10, 20, 50, 100]" size="small" background
				@size-change="handleDetailsSizeChange" @current-change="handleDetailsCurrentChange"
				layout="total, sizes, prev, pager, next, jumper" />
			<template #footer>
				<div class="dialog-footer">
					<el-button type="primary" @click="statedetail.details = false">关闭</el-button>
				</div>
			</template>
		</el-dialog>
	</div>
</template>


<script lang="ts" setup name="wareHous">
// 在顶部添加状态映射常量
const TASK_STATUS_MAP = {
	1: { text: '未开始', type: 'notstarted' },
	2: { text: '进行中', type: 'underay' },
	3: { text: '退回', type: 'warning' },
	4: { text: '已完成', type: 'success' },
	5: { text: '已取消', type: 'default' },
	6: { text: '异常', type: 'danger' }
};

const TaskTypeEnum =
{
	1: '暂存出库',
	2: '领料出库',
	3: '采货入库',
	4: '暂存入库',
	5: '其他入库（整托）',
	6: '其他入库（散托）',
	7: '回流入库'
};
const ActionTypeEnum = {
	0: '提升机升货',
	1: '取货',
	2: '举货',
	3: '送到库位点位',
	4: '卸货',
	5: '出库送货',
	6: '提升机下货',
};

const ActionStatusEnum = {
	0: '待处理',
	1: '已完成',
	2: '已失败',
	3: '已取消',

}

import { onMounted, computed, reactive, ref } from 'vue';
import { dayjs, ElMessage, ElMessageBox } from 'element-plus';
import EditWcstask from './component/editWcstask.vue';

import { getAPI } from '/@/utils/axios-utils';
import {
	WcstaskApi, WcstaskexportApi, DownloadWcstaskeApi, WcstaskeinportApi, GetAgvActionPageList, apiWcstaskEmergencyOperationPost,
	TemporarilyWcstaskeinportApi, apiUpdateAgvactionsPost, BatchTaskStartApi, BatchTaskCancelApi, BatchDeleteAPi,
} from '/@/api-services/apis/warehouse-wcstask-api'; // 导入 API 服务
import { WcstaskInput, DeleteTaskInput } from '/@/api-services/models/wcstask-input'; // 实体
import { Agvactions } from '/@/api-services/models/wcstask-agv-actions'; // 详情

import { apiEntranceApiFp } from '/@/api-services/apis/warehouse-entranceandexit-api';
import { allFooter } from 'md-editor-v3';
import { clone } from 'sortablejs';
import { color, number } from 'echarts';

// ...其他导入

const editEditWcstaskRef = ref<InstanceType<typeof EditWcstask>>();
//const detailsEditWcstaskRef = ref<InstanceType<typeof DetailsWcstask>>();

const state = reactive({
	loading: false,
	WcsData: [] as Array<WcstaskInput>,
	TaskDetails: [] as Array<WcstaskInput>,
	queryParams: {
		tasknumber: undefined,
		materialCode: undefined,
		Type: undefined
		
	},
	tableParams: {
		page: 1,
		pageSize: 50,
		total: 0,
	},

	editWcstaskTitle: '',

});
const Onclick = async (d: number) => {

const currentTaskNumber = getCurrentTaskNumber();
if (detailsselectedIds.value.length === 0) {
	ElMessage.error('请选择要操作的记录');
	return;
}
try {
	const res = await apiUpdateAgvactionsPost(detailsselectedIds.value);
	if (res.status == 200) {
		ElMessage.success('操作成功');

		if (currentTaskNumber) {
			console.log('当前任务的任务号是:', currentTaskNumber);
		} else {
			console.log('未选中任务，无法获取任务号');
		}
		Detail(currentTaskNumber);
	}
} catch (error) {
	ElMessage.error('操作失败');
}
};

const OnDclick = async (d: any) => {

const currentTaskNumber = d.taskId;

try {
// 假设 id 是从某个地方获取的，这里先简单假设存在一个变量 selectedId 存储单个 id
const selectedId = detailsselectedIds.value.map(item => item.id)[0]; // 取第一个选中项的 id，可根据实际情况调整
const idArray = [{ id: d.id }];
const res = await apiUpdateAgvactionsPost(idArray);
	if (res.status == 200) {
		ElMessage.success('操作成功');

		if (currentTaskNumber) {
			console.log('当前任务的任务号是:', currentTaskNumber);
		} else {
			console.log('未选中任务，无法获取任务号');
		}
		Detail(currentTaskNumber);
	}
} catch (error) {
	ElMessage.error('操作失败');
}
};



// 假设当前任务数据在某个选中行中，从 multipleSelection 中获取第一个选中行的 taskNumber
const getCurrentTaskNumber = () => {
	if (detailsselectedIds.value.length > 0) {
		console.log(JSON.stringify(detailsselectedIds.value[0].taskId));
		return detailsselectedIds.value[0].taskId;
	}
	return null;
}
// 使用示例，可根据实际情况调用此函数获取任务号
const OnTaskclick = async (d: number) => {

	try {
		if (selectedIds.value.length === 0) {
			ElMessage.error('请选择要操作的记录');
			return;
		}
		let res
		if (d == 1) {
			res = await BatchTaskStartApi(selectedIds.value.map(id => ({ id: id })));
		}
		else if (d == 2) {
			res = await BatchTaskCancelApi(selectedIds.value.map(id => ({ id: id })));
		}
		// 检查 res 是否存在，避免出现未定义错误
		if (res && res.status === 200) {
			ElMessage.success('操作成功');

			handleQuery();
		}
	} catch (error) {
		ElMessage.error('操作失败');
	}
};

const statedetail = reactive({
	AgvactionsData: [] as Array<Agvactions>,
	queryParams: {
		taskId: '',
		status: '',
		// page: '',
		// pageSize: ''
	},
	details: false,
	detailsWcstaskTitle: '',
	//详情分页参数
	detailsTableParams: {
		page: 1,
		pageSize: 20,
		total: 0,
	},
});

onMounted(async () => {
	//console.log('当前路由参数:', route); // 添加路由参数调试
	handleQuery();
	//await Detail({ taskId: "lalas" });
});



// 假设存在一个方法可以获取选中行的数据，这里我们先定义一个 ref 来存储选中的行
const multipleSelection = ref<DeleteTaskInput[]>([]);

const handleSelectionChange = (val: any[]) => {
	multipleSelection.value = val;
};
//var c = multipleSelection.value;//[123,456,333]
// 获取任务选中行的 idlist
const selectedIds = computed(() => multipleSelection.value.map(item => item.id));


const multipledetailsSelection = ref<DeleteTaskInput[]>([]);
const handleSelectiondetailsChange = (val: any[]) => {
	multipledetailsSelection.value = val;
};
//详情的选中行的idlist
const detailsselectedIds = computed(() => multipledetailsSelection.value.map(item => ({ id: item.id, taskId: item.taskId })));
//const selectedIds = computed(() => multipleSelection.value.map(item => ({id:item.id})));

const batchDeleteWcs = async () => {
	if (selectedIds.value.length === 0) {
		ElMessage.warning('请选择要删除的1行');
		return;
	}
// 引入 ElMessageBox

const batchDeleteWcs = async () => {
    if (selectedIds.value.length === 0) {
        ElMessage.warning('请选择要删除的行');
        return;
    }
    // 弹出确认对话框
    try {
        await ElMessageBox.confirm('确定要删除选中的任务吗？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        });
        // 用户点击确定后继续执行删除操作
        await BatchDeleteAPi(selectedIds.value.map(id => ({ id: id })));
        handleQuery(); // 刷新表格数据
        ElMessage.success('批量删除成功');
    } catch (error) {
        if (error === 'cancel') {
            ElMessage.info('已取消删除操作');
        } else {
            ElMessage.error('批量删除失败');
        }
    }
};
	//console.log(selectedIds.value);
	try {
		await BatchDeleteAPi(selectedIds.value.map(id => ({ id: id })));
		handleQuery(); // 刷新表格数据
		ElMessage.success('批量删除成功');
	} catch (error) {
		ElMessage.error('批量删除失败');
	}
};
// 查询操作
const handleQuery = async () => {
	state.loading = true;

	try {

		const res = await getAPI(WcstaskApi).apiWcstaskPagePost({
			...state.queryParams,
			page: state.tableParams.page,
			pageSize: state.tableParams.pageSize,
		});
		state.WcsData = res.data.result?.items || [];
		state.tableParams.total = res.data?.result?.total ?? 0;

	} catch {
		state.WcsData = [];
		state.tableParams.total = 0;
	}

	finally {
		state.loading = false;

	}
};

// 重置操作
const resetQuery = () => {
	state.queryParams.tasknumber = undefined;
	state.queryParams.materialCode = undefined;
	handleQuery();
};

// 打开新增页面
const add = () => {
	// alert(JSON.stringify(selectedIds.value));
	const addData = {
		description: null,
		total: null,
		attachment: null,
		isenable: 1,
	};
	state.editWcstaskTitle = '添加WCS任务';
	//console.error('打开添加页面:', error);
	editEditWcstaskRef.value?.openDialog(addData);
};
const Detail = async (row: any) => {
	statedetail.detailsWcstaskTitle = '任务下发步骤';
	try {

		const newQueryParams = {
			taskId: row, // 示例任务 ID
			status: row, // 示例状态
			// page: statedetail.detailsTableParams.page,
			// pageSize: statedetail.detailsTableParams.pageSize
		};
		statedetail.queryParams = newQueryParams;
		const res = await GetAgvActionPageList({

			...statedetail.queryParams,
			page: statedetail.detailsTableParams.page,
			pageSize: statedetail.detailsTableParams.pageSize,
		});
		statedetail.details = true;
		statedetail.AgvactionsData = res.data.result?.items || [];
		statedetail.detailsTableParams.total = res.data?.result?.total ?? 0;

		if (statedetail.AgvactionsData.length === 0) {
			ElMessage.warning('任务详情为空');
		}

	} catch (error) {
		console.error('获取任务详情失败', error);
		ElMessage.error('获取任务详情失败，请稍后重试');
	}
};


// 关闭新增页面
const closeAddDialog = () => {
	editEditWcstaskRef.value?.openDialog(false);
};


// 打开编辑页面
const openEditWarehous = (row: any) => {
	state.editWcstaskTitle = '编辑WCS任务';
	editEditWcstaskRef.value?.openDialog(row);
};

// 删除操作
const delWarehous = (row: any) => {
	ElMessageBox.confirm(`确定删除任务：【${row.taskNumber}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			try {
				await getAPI(WcstaskApi).apiWcstaskDeletePost({ id: row.id, taskId: row.taskNumber });
				handleQuery();
				ElMessage.success('删除成功');
			} catch (error) {
				//console.error('删除失败:', error);
				ElMessage.error('删除失败，请稍后重试');
			}
		})
		.catch(() => {
			ElMessage.info('已取消删除');
		});
};

import { downloadByData, getFileName } from '/@/utils/download';
import { json } from 'stream/consumers';

const exportDate = async () => {
	try {
		state.loading = true;
		// 通常导出文件时需要设置 responseType 为 'blob'，以正确处理二进制数据
		// 为了解决类型不匹配问题，将 responseType 单独传递
		const config = { responseType: 'blob' };
		var res = await WcstaskexportApi(state.queryParams);
		state.loading = false;
		var fileName = getFileName(res.headers);
		// 假设增加一些日志记录，方便调试
		downloadByData(res.data as any, fileName);
		ElMessage.success('导出成功' + fileName);
	}
	catch (error) {
		state.loading = false;
		ElMessage.error('导出失败');
	}
}

// #region 导入
// 上传前校验
const beforeUpload = (file: File) => {
	const isExcel = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
		file.type === 'application/vnd.ms-excel'
	if (!isExcel) {
		ElMessage.error('只能上传 Excel 文件!')
		return false
	}
	return true
}
// 自定义上传方法
const handleUpload = async (options: any) => {
  const formData = new FormData()
  formData.append('file', options.file)
  try {
    const response = await WcstaskeinportApi(formData);
    handleUploadSuccess(response);
  } catch (error) {
    handleUploadError(error);
  }
}

// 上传成功回调
const handleUploadSuccess = async (response: any) => {
	//console.log('response', response);
	if (response.status === 200) {
		ElMessage.success('导入成功')
		handleQuery() // 刷新表格数据
	}
	else {
		ElMessage.error(response.message || '导入失败!')
	}
}

// 上传失败回调
const handleUploadError = (error: any) => {
	ElMessage.error(error.message || '导入失败' + error.message)
}




// 暂存出库
const TemporarilyhandleUpload = async (options: any) => {
	const formData = new FormData()
	formData.append('file', options.file)
	// 这里调用你的上传API
	//console.log('handleUpload', formData);
	try {

		const response = await TemporarilyWcstaskeinportApi(formData).then((response) => {
			console.log('response', response);
			TemporarilyhandleUploadSuccess(response);

		})

	} catch (error) {
		console.log('error', error);
		TemporarilyhandleUploadError(error);
	}
}

// 上传成功回调
const TemporarilyhandleUploadSuccess = async (response: any) => {
	console.log('response', response);
	if (response.status === 200) {
		ElMessage.success('导入成功')
		handleQuery() // 刷新表格数据
	}
	else {
		ElMessage.error(response.message || '导入失败!')
	}
}

// 上传失败回调
const TemporarilyhandleUploadError = (error: any) => {
	ElMessage.error(error.message || '导入失败' + error.message)
}

/**
 * 下载模板
 */
const downloadTemplate = async () => {
	try {
		DownloadWcstaskeApi().then((response) => {

			const blob = new Blob([response.data])
			const fileName = getFileName(response.headers);
			downloadByData(response.data as any, fileName);

			ElMessage.success(`下载成功${fileName}`);
		}); // 调用下载模板的API

	} catch (error) {
		ElMessage.error('下载失败');
	}
};

// 优先下发
const emergencyOperation = async () => {
	try {
		// 检查是否有选中行
		if (selectedIds.value.length === 0) {
			ElMessage.error('请选择要优先下发的任务');
			return;
		}
		else {
			// 调用 API 进行优先下发操作
			const idObjects = selectedIds.value.map(id => ({ id }));
			// alert(JSON.stringify(idObjects));
			await apiWcstaskEmergencyOperationPost(idObjects);
			ElMessage.success('优先下发成功');
			handleQuery(); // 刷新表格数据
		}
	} catch (error) {
		// 处理优先下发操作中的错误
		ElMessage.error('优先下发失败，请稍后重试');
	}

}

const outWarehous = async () => {
	try {
		// 检查是否有选中行
		if (selectedIds.value.length === 0) {
			ElMessage.error('请选择要优先出库的任务');
			return;
		}
		else {
			// 调用 API 进行优先下发操作
			await apiWcstaskEmergencyOperationPost(selectedIds.value.map(id => ({ id })));
			ElMessage.success('出库下发成功');
			handleQuery(); // 刷新表格数据
		}
	} catch (error) {
		// 处理优先下发操作中的错误
		ElMessage.error('出库下发失败，请稍后重试');
	}

}


// 改变页面容量
const handleSizeChange = (val: number) => {
	state.tableParams.pageSize = val;
	handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
	state.tableParams.page = val;
	handleQuery();
};
// 改变详情页面容量

const handleDetailsSizeChange = async (val: number) => {
  statedetail.detailsTableParams.pageSize = val;
  await loadDetailsData();
};

const handleDetailsCurrentChange = async (val: number) => {
  statedetail.detailsTableParams.page = val;
  await loadDetailsData();
};
//重新刷新全部
const loadDetailsData = async () => {
  try {
    const res = await GetAgvActionPageList({
      ...statedetail.queryParams,
      page: statedetail.detailsTableParams.page,
      pageSize: statedetail.detailsTableParams.pageSize,
    });
    statedetail.AgvactionsData = res.data.result?.items || [];
    statedetail.detailsTableParams.total = res.data?.result?.total ?? 0;
  } catch (error) {
    console.error('获取详情数据失败', error);
    ElMessage.error('获取详情数据失败，请稍后重试');
  }
};
</script>
